﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace GenericLibrary.ExtensionMethods {

    public static class FileStreamExtension {

        public static FileStream AsReadOnly(this FileStream fs) {
            try {
                fs.Close();
                return new FileStream(fs.Name, FileMode.Open, FileAccess.Read);
            } catch(Exception) {
                Debug.Assert(false);
                throw;
            }
        }

        public static FileStream AsWriteOnly(this FileStream fs) {
            try {
                fs.Close();
                return new FileStream(fs.Name, FileMode.OpenOrCreate, FileAccess.Write);
            } catch(Exception) {
                Debug.Assert(false);
                throw;
            }
        }

        public static void Delete(this FileStream fs) {
            try {
                fs.Close();
                File.Delete(fs.Name);
            } catch(Exception) {
                Debug.Assert(false);
                throw;
            }
        }
    }
}
